package search;
/**
 * GraphEdge is an abstract class representing transitions in the state space
 * for some problem. The transitions are between two GraphNode objects 
 * which represent the "source" node (before the transition is taken)
 * and the resulting node after the transition has been taken.
 * 
 * @author Rudi Lutz 
 * @version 1.0
 */

public abstract class GraphEdge<L,N extends GraphNode<?>>
{
    private N node1;
    private N node2;
    private L label;
    
    /** This constructor takes two parameters representing the 2 nodes involved
     * @param node1 the original node
     * @param node2 the node after the transition has been taken
     */
    public GraphEdge(N node1, N node2)
    {
        this.node1 = node1;
        this.node2 = node2;
    }
    
    /** This constructor takes two parameters representing the 2 nodes involved
     * and a parameter representing the label on the transition
     * @param node1 the original node
     * @param node2 the node after the transition has been taken
     * @param label the label
     */
    public GraphEdge(N node1, N node2, L label)
    {
        this.node1 = node1;
        this.node2 = node2;
        this.label = label;
    }
    
    /**
     * @return the "source" node
     */
    public N getNode1()
    {
        return node1;
    }
    
    /**
     * @return the destination node
     */
    public N getNode2()
    {
        return node2;
    }
    
    /** given a node at one end of a transition this computes the node at the other end
     * @param n a node at one end of the transition
     * @return the node at the other end
     */
    public N getOppositeEnd(N n)
    {
        if (n == node1) {
            return node2;
        }
        else {
            return node1;
        }
    }
    
    /**
     * @return the label for the transition
     */
    public L getLabel()
    {
        return label;
    }
    /**
     * This must be provided in any implementing class
     * @return the application specific cost of the transition
     */
    public abstract double getCost();
}
